package com.chf.job.controller;

import com.chf.job.common.Const;
import com.chf.job.common.ServerResponse;
import com.chf.job.pojo.Deliver;
import com.chf.job.pojo.User;
import com.chf.job.service.DeliverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class DeliverController {
    @Autowired
    private DeliverService deliverService;

    /**
     * 投递简历
     */
    @PostMapping("deliver/sendResume.html")
    @ResponseBody
    public ServerResponse sendResume(Deliver deliver, HttpServletRequest request) {
        User user = (User) request.getSession(true).getAttribute(Const.CURRENT_USER);
        int result = deliverService.addDeliver(deliver, user.getEmail());
        if (result > 0) {
            return ServerResponse.createBySuccessMessage("投递成功");
        }
        return ServerResponse.createBySuccessMessage("投递失败");
    }

    /**
     * 通知面试简历
     */
    @GetMapping("deliver/updateDeliverStatus.html")
    @ResponseBody
    public ServerResponse updateDeliverStatus(@RequestParam("email") String email, @RequestParam("status") Integer status, HttpServletRequest request) {
        User user = (User) request.getSession(true).getAttribute(Const.CURRENT_USER);
        int result = deliverService.updateDeliverStatus(email, status,user.getEmail());
        if (result > 0) {
            return ServerResponse.createBySuccess("投递成功", Const.UNTREATED_RESUME);
        }
        return ServerResponse.createByErrorMessage("投递失败");
    }

}
